package com.woniuxy.car.commodity.service.core.controller;


import com.woniuxy.car.commodity.service.core.dto.CommodityCommentDto;
import com.woniuxy.car.commodity.service.core.service.ICommodityCommentService;
import com.woniuxy.common.api.CommonResult;
import com.woniuxy.common.api.enums.ResultCode;
import com.woniuxy.common.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品评论表 前端控制器
 * </p>
 *
 * @author awz
 * @since 2022-03-01
 */
@AllArgsConstructor
@Api(tags = "商品评价接口")
@RestController
@RequestMapping("/commodity/commodity-comment")
public class CommodityCommentController {

    private ICommodityCommentService commodityCommentService;

    @ApiOperation("添加商品评价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commodityCommentDto", value = "商品评价dto")
    })
    @PostMapping("/addCommodityComment")
    public CommonResult<Boolean> addCommodityComment(@RequestBody CommodityCommentDto commodityCommentDto){
        //获取用户id
        int userId = 1;
        //获取用户ip
        String userIp = "0.0.0.0";
        commodityCommentDto.setUserIp(userIp);
        commodityCommentDto.setUserId(userId);
        try {
            commodityCommentService.addCommodityComment(commodityCommentDto);
        } catch (BusinessException e) {
            return CommonResult.failure(ResultCode.PARAM_IS_BLANK.getCode(), e.getMessage());
        }

        return CommonResult.success(true);

    }
}
